package com.nervenets.web.controller.handler.admin.user;

import com.nervenets.web.controller.handler.SessionHandler;
import com.nervenets.web.enumeration.OperateType;
import com.nervenets.web.enumeration.Role;
import com.nervenets.web.enumeration.WealthType;
import com.nervenets.web.redis.domain.user.WealthOfMoneyByOperateType;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Joe on 2018/1/25.
 */
public class UserOperateTypeMoneyCountHandler extends SessionHandler<TargetUserIdParams> {
    @Override
    public ArrayList<Role> allowRoles() {
        return Role.administrator();
    }

    @Override
    public boolean needLog() {
        return false;
    }

    @Override
    public String handle(TargetUserIdParams params, HttpServletRequest request) throws Exception {
        int targetUserId = params.getTargetUserId();
        long total = globalService.getUserWealthOfTotalMoney(targetUserId, WealthType.money);
        long left = globalService.getUserWealthOfMoney(targetUserId, WealthType.money);
        List<WealthOfMoneyByOperateType> values = new ArrayList<>();
        for (OperateType operateType : OperateType.values()) {
            values.add(globalService.getUserWealthOfMoneyByOperateType(targetUserId, operateType, WealthType.money));
        }
        return successMessage(new Model(total, left, values));
    }

    @Override
    public String result() throws Exception {
        return null;
    }

    class Model {
        private long total;
        private long left;
        private List<WealthOfMoneyByOperateType> values;

        public Model(long total, long left, List<WealthOfMoneyByOperateType> values) {
            this.total = total;
            this.left = left;
            this.values = values;
        }
    }
}
